home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 112 (1989-11-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 112 (1989-11-15)(Ossowski, Stefan)(DE)(PD).adf / Mischief / TimerDevice.c < prev   
C/C++ Source or Header  |  1989-07-05  |  2KB  |  88 lines

  1. /* TimerDevice.c ************************************************************
  2. *
  3. *    TimerDevice ---    Some useful timer.device control routines.
  4. *
  5. *    Author --------    Olaf Barthel, ED Electronic Design Hannover
  6. *            Brabeckstrasse 35
  7. *            D-3000 Hannover 71
  8. *
  9. *            Federal Republic of Germany
  10. *
  11. ****************************************************************************/
  12.  
  13. #include <exec/types.h>
  14. #include <devices/timer.h>
  15. #include <exec/memory.h>
  16.  
  17.     /* Structures we need, these don't need to be visible to
  18.      * other modules.
  19.      */
  20.  
  21. struct timerequest    *tr_TimerRequest= NULL,*AllocMem();
  22. struct MsgPort        *tr_TimerPort    = NULL,*CreatePort();
  23.  
  24.     /* CloseTimerDevice() :
  25.      *
  26.      *    Deallocate the control structures.
  27.      */
  28.  
  29. void
  30. CloseTimerDevice()
  31. {
  32.     if(tr_TimerRequest)
  33.     {
  34.         CloseDevice(tr_TimerRequest);
  35.         FreeMem(tr_TimerRequest,sizeof(struct timerequest));
  36.     }
  37.  
  38.     if(tr_TimerPort)
  39.         DeletePort(tr_TimerPort);
  40. }
  41.  
  42.     /* OpenTimerDevice() :
  43.      *
  44.      *    Initialize the precision timer.
  45.      */
  46.  
  47. BOOL
  48. OpenTimerDevice()
  49. {
  50.     if(!(tr_TimerPort = (struct MsgPort *)CreatePort(NULL,0)))
  51.         return(FALSE);
  52.  
  53.     if(!(tr_TimerRequest = (struct timerequest *)AllocMem(sizeof(struct timerequest),MEMF_PUBLIC | MEMF_CLEAR)))
  54.     {
  55.         DeletePort(tr_TimerPort);
  56.         return(FALSE);
  57.     }
  58.  
  59.     if(OpenDevice(TIMERNAME,UNIT_VBLANK,tr_TimerRequest,0))
  60.     {
  61.         FreeMem(tr_TimerRequest,sizeof(struct timerequest));
  62.         DeletePort(tr_TimerPort);
  63.         return(FALSE);
  64.     }
  65.  
  66.     tr_TimerRequest -> tr_node . io_Message . mn_ReplyPort    = tr_TimerPort;
  67.     tr_TimerRequest -> tr_node . io_Command            = TR_ADDREQUEST;
  68.     tr_TimerRequest -> tr_node . io_Flags            = 0;
  69.     tr_TimerRequest -> tr_node . io_Error            = 0;
  70.  
  71.     return(TRUE);
  72. }
  73.  
  74.     /* WaitTime(Seconds,Micros) :
  75.      *
  76.      *    Wait a period of time.
  77.      */
  78.  
  79. void
  80. WaitTime(Seconds,Micros)
  81. register ULONG Seconds,Micros;
  82. {
  83.     tr_TimerRequest -> tr_time . tv_secs    = Seconds;
  84.     tr_TimerRequest -> tr_time . tv_micro    = Micros;
  85.  
  86.     DoIO(tr_TimerRequest);
  87. }
  88.